<?php

	include_once("cmsConfig.php");
		
	class CmsOrderItem extends CmsKVC  {
		
		var $quantity;
		
		function CmsOrderItem(){
			parent::CmsKVC();
			$this->keys = array_merge_recursive(
				array(				
						EXTRACT_NUMBER =>array("quantity")
				),
				$this->keys
			);
			$this->requiredKeys = array_merge(
				array("quantity"), 
				$this->requiredKeys
			);
			
			$this->dataModelKeyMapping = array_merge(
				$this->dataModelKeyMapping,
				array(
					//"orderItemType" => "title",
					"orderContainer" => "author",
					"price" => "value",
					"subTotal" => "inhouse",					
					//"orderItemStatus" => "restricted",
					"quantity" => "extra4"
				));			
			
			
			$this->formId = 168;
			$this->documentTypeCode = 'docOdrItm';			
		}
		
		
		//
		function validateForSave(){
			$valid = parent::validateForSave();
			if ($this->valueForKey('quantity') <= 0 ) $valid = false;
			return $valid;
		}
		
		//quantity is not nullable.. either a number or zero.. scalar value
		//cant set the price.. so we dont really need to return a reference
		function price(){
			return 0;
		}
		
		//abstract method to get the products document.
		function getProductDocument(){
			return 0;
		}
		
		//quantity is not nullable.. either a number or zero.. scalar value
		//setables are changable.. return a reference
		function quantity(){
			if (is_null($this->quantity))
				$this->quantity = 0;
			if ($this->quantity < 0 )
				$this->quantity = 0;
			return $this->quantity;
		}
		
		function setQuantity($quantity) {
			//must be greater than zero.. whole number.. round/trunc
			$this->quantity = (int)$quantity;
			
			if (is_null($this->quantity)) $this->quantity = 0;

			if ($this->quantity < 0 ) $this->quantity = 0;
				
		}

		function isEmpty() {
			$isEmpty = parent::isEmpty();
			//if the parent is not empty we can return..
			if (!$isEmpty) return false;
			
			//check quantity..  price does not matter..
			$isEmpty = $isEmpty && $this->valueForKey('quantity') == 0;
			
			return $isEmpty;
		}
		
		function orderItemImageUrl($size){// if this was java i would be abstract..
			return null;
		}
		
	}